//
//  PSFilterMissingSuits.m
//  PrefCore
//
//  Created by Sergey on 6/12/14.
//  Copyright (c) 2014 Play-on-smart. All rights reserved.
//

#import "PSFilter.h"
#import "PSGame.h"

// Must be called only for the first hand
PSHandHash PSFilterMissingSuits(
    PSHandHash candidates
,   PSHandHash* hands
,   PSPlayerId player
) {
    // Get the remaining cards in opponent hands as one big hand
    PSHandHash oh = hands[PSGameNextPlayerId(player)] | hands[PSGamePreviousPlayerId(player)];
    PSHandHash result = 0;

    if (PSHandGetSuit(oh, kSuitSpades)) {
        result = PSHandAddSuit(result, kSuitSpades, candidates);
    }
    if (PSHandGetSuit(oh, kSuitClubs)) {
        result = PSHandAddSuit(result, kSuitClubs, candidates);
    }
    if (PSHandGetSuit(oh, kSuitDiamonds)) {
        result = PSHandAddSuit(result, kSuitDiamonds, candidates);
    }
    if (PSHandGetSuit(oh, kSuitHearts)) {
        result = PSHandAddSuit(result, kSuitHearts, candidates);
    }

    // Only if filtered hand has cards:
    // when only missing suits are left, just peek one card, no matter which one:
    return result == 0 ? PSHandGetFirstCard(candidates) : result;
}
